/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FAtable.java
 *
 * Created on 08-oct-2011, 16:41:17
 */
package gui.ventanas;

import automatas.*;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Arturo
 */
public class FAtable extends javax.swing.JPanel {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** Creates new form FAtable */
    FA fa;

    public FAtable() {
        initComponents();
        
        jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    }

    public void setAutomata(FA automata) {
        fa = automata.clonar();
        ArrayList<String> columnas = new ArrayList<String>();
        columnas.add("Nodo");
        for (char letra : fa.getAlfabeto().letras) {
            columnas.add(letra + "");
        }
        DefaultTableModel modelo = new DefaultTableModel(columnas.toArray(), 0);
        for (Nodo nodo : fa.getNodos()) {
            String aAgregar = "";
            ArrayList<String> fila = new ArrayList<String>();
            aAgregar = nodo.getNombre();
            if (fa.getInicial().equals(nodo)) aAgregar += "(Inicial)";
            if (fa.getFinales().contains(nodo)) aAgregar += "(Final)";
            fila.add(aAgregar);
            
            for (char letra : fa.getAlfabeto().letras) {
                List<Nodo> apuntados = nodo.getApuntados().get(letra + "");
                if (apuntados == null )fila.add("");
                else fila.add(apuntados.toString());
            }
            modelo.addRow(fila.toArray());
        }
        jTable1.setModel(modelo);
    }

    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setName("Form"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.setFocusable(false);
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
